package com.hanthink.web.controller.delivery;

import java.util.List;

import com.hanthink.common.core.domain.model.LoginUser;
import com.hanthink.common.utils.ServletUtils;
import com.hanthink.framework.web.service.TokenService;
import com.hanthink.system.domain.logistics.ProductionDeliveryPlan;
import com.hanthink.system.service.logistics.IProductionDeliveryPlanService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hanthink.common.annotation.Log;
import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.domain.AjaxResult;
import com.hanthink.common.enums.BusinessType;
import com.hanthink.system.domain.delivery.DeliveryProductionDeliveryPlan;
import com.hanthink.system.service.delivery.IDeliveryProductionDeliveryPlanService;
import com.hanthink.common.utils.poi.ExcelUtil;
import com.hanthink.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 运输计划管理Controller
 * 
 * @author hanthink
 * @date 2022-09-05
 */
@RestController
@RequestMapping("/delivery/ProductionDeliveryPlan")
public class DeliveryProductionDeliveryPlanController extends BaseController
{
    @Autowired
    private IDeliveryProductionDeliveryPlanService productionDeliveryPlanService;

    @Autowired
    private TokenService tokenService;
    /**
     * 查询运输计划管理列表
     */
    @PreAuthorize("@ss.hasPermi('delivery:ProductionDeliveryPlan:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeliveryProductionDeliveryPlan productionDeliveryPlan)
    {
        startPage();
        List<DeliveryProductionDeliveryPlan> list = productionDeliveryPlanService.selectProductionDeliveryPlanList(productionDeliveryPlan);
        return getDataTable(list);
    }

    // fmc add----------------
    @Log(title = "运输计划数据填报", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('delivery:ProductionDeliveryPlan:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<DeliveryProductionDeliveryPlan> util = new ExcelUtil<DeliveryProductionDeliveryPlan>(DeliveryProductionDeliveryPlan.class);
        List<DeliveryProductionDeliveryPlan> itemList = util.importExcel(file.getInputStream());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        String message = productionDeliveryPlanService.importDeliveryPlan(itemList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    //----end

    @GetMapping("/importTemplate") // 下载导入模板 fmc
    public AjaxResult importTemplate() {
        ExcelUtil<DeliveryProductionDeliveryPlan> util = new ExcelUtil<DeliveryProductionDeliveryPlan>(DeliveryProductionDeliveryPlan.class);
        return util.importTemplateExcel("运输计划导入模板");
    }
    /**
     * 导出运输计划管理列表
     */
    @PreAuthorize("@ss.hasPermi('delivery:ProductionDeliveryPlan:export')")
    @Log(title = "运输计划管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DeliveryProductionDeliveryPlan productionDeliveryPlan)
    {
        List<DeliveryProductionDeliveryPlan> list = productionDeliveryPlanService.selectProductionDeliveryPlanList(productionDeliveryPlan);
        ExcelUtil<DeliveryProductionDeliveryPlan> util = new ExcelUtil<DeliveryProductionDeliveryPlan>(DeliveryProductionDeliveryPlan.class);
        return util.exportExcel(list, "ProductionDeliveryPlan");
    }

    /**
     * 获取运输计划管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('delivery:ProductionDeliveryPlan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(productionDeliveryPlanService.selectProductionDeliveryPlanById(id));
    }

    /**
     * 新增运输计划管理
     */
    @PreAuthorize("@ss.hasPermi('delivery:ProductionDeliveryPlan:add')")
    @Log(title = "运输计划管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeliveryProductionDeliveryPlan productionDeliveryPlan)
    {
        return toAjax(productionDeliveryPlanService.insertProductionDeliveryPlan(productionDeliveryPlan));
    }

    /**
     * 修改运输计划管理
     */
    @PreAuthorize("@ss.hasPermi('delivery:ProductionDeliveryPlan:edit')")
    @Log(title = "运输计划管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeliveryProductionDeliveryPlan productionDeliveryPlan)
    {
        return toAjax(productionDeliveryPlanService.updateProductionDeliveryPlan(productionDeliveryPlan));
    }

    /**
     * 删除运输计划管理
     */
    @PreAuthorize("@ss.hasPermi('delivery:ProductionDeliveryPlan:remove')")
    @Log(title = "运输计划管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productionDeliveryPlanService.deleteProductionDeliveryPlanByIds(ids));
    }
}
